<?php
declare (strict_types = 1);

namespace app\admin\service\system;

use app\admin\logic\system\Log as LogLogic;
use app\common\service\BaseService;
use eduline\admin\libs\pageform\FormItem;
use eduline\admin\libs\pagelist\ListItem;
use eduline\admin\page\PageList;
use think\facade\Request;

class Log extends BaseService
{
    /**
     * 日志列表
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-06-17
     * @return   [type]                         [description]
     */
    public function index()
    {
        // 搜索功能
        $map                                         = [];
        $phone = '';
        Request::has('phone', 'get', true) && $map['phone'] = Request::get('phone/s');
        Request::has('date','get') && $map['create_time'] = Request::get('date/a');

        $datas                                       = app(LogLogic::class)->getList($map);
        // 定义字段
        $keyList = [
			'user_name'     => ListItem::make('custom')->title('操作者'),
            'log_type_text' => ListItem::make()->title('操作'),
            'content'       => ListItem::make()->title('操作内容'),
            'ip'            => ListItem::make()->title('操作IP'),
            'create_time'   => ListItem::make()->title('操作时间'),
        ];

        $searchKey = [
            'date'  => FormItem::make('date')->title(false)->dateType(FormItem::option('DateType', 'DATETIME_RANGE'))->startPlaceholder()->endPlaceholder()->format('yyyy-MM-dd HH:mm'),
            'phone' => FormItem::make('input')->title(false)->placeholder('操作者手机号'),

        ];

        // 设置表单
        $list = app(PageList::class);
        // 表单字段
        $list->pageKey   = $keyList;
        $list->searchKey = $searchKey;
        $list->datas     = $datas;

        return $list->send();
    }
}
